package com.example.xiongmao.mapper;

import com.example.xiongmao.anno.AutoFill;
import com.example.xiongmao.entity.DTO.user.UserChargeDTO;
import com.example.xiongmao.entity.DTO.user.addUserChargeDTO;
import com.example.xiongmao.entity.VO.user.userChargeVO;
import com.example.xiongmao.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserChargeMapper {
    /**
     * 展示用户
     *
     * @param userChargeDTO
     * @return
     */
    List<userChargeVO> list(UserChargeDTO userChargeDTO);

    /**
     * 添加用户
     *
     * @param addUser
     */
    @AutoFill(OperationType.INSERT)
    @Insert("INSERT INTO users (username, password, email, phone_number, img_url, created_time, updated_time, status) " +
            "VALUES (#{username}, '123456', #{email}, #{phoneNumber}, #{imgUrl}, #{createdTime}, #{updatedTime}, #{status})")
    void add(addUserChargeDTO addUser);

    /**
     * 编辑回显
     *
     * @param id
     * @return
     */
    @Select("select * from users where id = #{id}")
    userChargeVO getById(Integer id);


    /**
     * 编辑用户
     *
     * @param updateUser
     */
    @AutoFill(OperationType.UPDATE)
    void updateUser(addUserChargeDTO updateUser);

    /**
     * （批量）删除用户信息
     *
     * @param ids
     */
    void deleteUserBatch(List<Integer> ids);

    // 禁用
    @AutoFill(OperationType.UPDATE)
    @Update("update users set status=0 where id =#{id}")
    void userDisable(Long id);

    // 正常
    @AutoFill(OperationType.UPDATE)
    @Update("update users set status=1 where id =#{id}")
    void userunDisable(Long id);
}
